import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
//导入element组件
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
//引入Echarts图表
import echarts from '@/utils/Echarts';
//引入moment时间转换组件
//导入富文本编辑器
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';

//axios 拦截器
//  不需要的放在白名单列表
import axios from 'axios';
const baimingdan = ['/login'];

axios.interceptors.request.use(
  function (config: any) {
    // 在发送请求之前做些什么
    const fangxing = config.url;
    const panduan = baimingdan.findIndex((path) => fangxing.includes(path));
    if (panduan !== -1) {
      // console.log(`${fangxing} 不需要`);
    } else {
      // console.log(`${fangxing} 需要`);
      config.headers['Authorization'] = sessionStorage.getItem('token');
    }
    return config;
  },
  function (error: any) {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.use(ElementPlus, {
  locale: zhCn,
});
app.config.globalProperties.$echarts = echarts; //引入组件
// app.filter('data', function (tiem: Date) {
//   const dt = new Date(tiem);
//   const y = dt.getFullYear();
//   const m = (dt.getMonth() + 1 + '').padStart(2, '0');
//   const d = (dt.getDate() + '').padStart(2, '0');
//   const hh = (dt.getHours() + '').padStart(2, '0');
//   const mm = (dt.getMinutes() + '').padStart(2, '0');
//   const ss = (dt.getSeconds() + '').padStart(2, '0');
// });

// //添加全局日期过滤器vue3.0的写法，2.0参考官方写法
// app.config.globalProperties.$filters = {
//   format(value: string) {
//     if (value) {
//       return dayjs(value).format('YYYY-MM-DD');
//     } else {
//       return '';
//     }
//   },
// };

app.component('QuillEditor', QuillEditor);

app.use(store).use(router).mount('#app');
